import http from "../util/http";
import store from "../store";
import router from "../router";

export function userLogin(data) {
    return new Promise((resolve, reject) => {
        http.post("login", data).then(res => {
            if (res.success === true) {
                store.dispatch('user/userLogin', res.data.access_token);
                router.push('/');
            } else {
                reject(res.msg);
            }
        }).catch(res => {
            console.log(res);
        });
    });
}

export function isLogin() {
    console.log(store.state.user);
    if (store.getters["user/getToken"] !== '') {
        return true;
    }
    return false;
}
